package mainillnessname;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import bingliandshuju.SingleDataofAll;

import com.example.animaldoctor03.AllIllness;
import com.example.animaldoctor03.BiaoGuanZhengZhuang;
import com.example.animaldoctor03.R;

import Modle.disease.ClinicalSymptomsKey;
import commonClass.ADAQueryAllDiseaseInfoByAnimalDiseaseCategorieIDAction;
import commonClass.ADAQueryClinicalSymptomsKeyByDiseaseIDAction;
import commonClass.FunctionDispatcher;
import commonClass.RemoteActionsName;
import commonClass.FunctionDispatcher.IRequestCompeletListener;
import Modle.disease.Disease;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Notification.Builder;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ListView;

public class PossibleZZ extends Activity {

	private Button buttonofYes = null ;
	private ListView listofPZZ = null;
	private String IDofPZZ = "" ;
	private ArrayList<Object> resultListofPZZ = null;
	private void CSHPZZ(){
		setContentView(R.layout.possiblezz);
		buttonofYes = (Button)findViewById(R.id.buttonofPZZ1);
		
		listofPZZ = (ListView)findViewById(R.id.listofPZZ);
	
	}
private void getInformationofPZZ(){
	Intent intentofpZZ = getIntent();
	Bundle bundleofPZZ = intentofpZZ.getExtras();
	Disease informationofPZZ = (Disease)bundleofPZZ.get("shuju");
	IDofPZZ = informationofPZZ.getDiseaseID();
	
	
	
}

private ArrayList<Object> assemblyofPZZ() {

	getInformationofPZZ();
	ArrayList<Object> list = new ArrayList<Object>();

	list.add(IDofPZZ);
	return list;
}

private void bindingofPZZ(final ArrayList<Object> list) {
	try{
	final String[] resultofPZZ = new String[list.size()];
	// list.toArray(new String[list.size()]);
	for (int i = 0; i < list.size(); i++) {
		
		System.out.println("###############  of  this  " +  ((ClinicalSymptomsKey)list.get(i)).getClinicalSymptomsKey() + "88888");
		
		//haiyouwenti
		resultofPZZ[i] =((ClinicalSymptomsKey)list.get(i)).getClinicalSymptomsKey() ;
	}
	final ArrayAdapter<String> arrayAdapterofPZZ = new ArrayAdapter<String>(
			this, android.R.layout.simple_list_item_multiple_choice, resultofPZZ);
	listofPZZ.setAdapter(arrayAdapterofPZZ);
	
	listofPZZ.setOnItemClickListener(new OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position,
				long id) {
			// TODO Auto-generated method stub
			
		}
	});
	

	
	buttonofYes.setOnClickListener(new OnClickListener() {
		

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			
		 List<Object> arrlistofPZZ = new ArrayList <Object>();
			for(long ids : listofPZZ.getCheckItemIds() ){
				
				int i = (int) ids;
				
				arrlistofPZZ.add((ClinicalSymptomsKey)list.get(i));
				
			}
			if(arrlistofPZZ.size() >0){
				
			SingleDataofAll singleDataofPZZ = SingleDataofAll.getInstance();
			singleDataofPZZ.setListinformation(arrlistofPZZ);
			Bundle bundlleofPZZ = new Bundle();
			bundlleofPZZ.putSerializable("shuju", (Serializable) arrlistofPZZ);
			Intent intentofPZZ = new Intent(PossibleZZ.this , AllIllness.class);
			intentofPZZ.putExtras(bundlleofPZZ);
			startActivity(intentofPZZ);
			finish();
			}
			else{
				android.app.AlertDialog.Builder builderofPZZ = new AlertDialog.Builder(PossibleZZ.this);
				builderofPZZ.setMessage("请选择");
				builderofPZZ.create().show();
			}
			
		}
	});
	}catch(NullPointerException e){
		android.app.AlertDialog.Builder builderofPZZ = new AlertDialog.Builder(PossibleZZ.this);
		builderofPZZ.setMessage("无数据 , 请用其他功能");
		builderofPZZ.create().show();
	}
}
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		CSHPZZ();
		assemblyofPZZ();
		ArrayList<Object> parasListofPZZ= assemblyofPZZ();
		
		final ArrayList<Object> resultListTofPZZ = null;
		ADAQueryClinicalSymptomsKeyByDiseaseIDAction iActionofPZZ = new ADAQueryClinicalSymptomsKeyByDiseaseIDAction();
		FunctionDispatcher functionDispacherofPZZ = new FunctionDispatcher();
	try{	
		functionDispacherofPZZ.exceute(RemoteActionsName.QueryClinicalSymptomsKeyByDiseaseIDAction, parasListofPZZ, iActionofPZZ, new IRequestCompeletListener() {

			@Override
			public void doCompelet(ArrayList<Object> resultList) {
				// TODO Auto-generated method stub
		
				PossibleZZ.this.resultListofPZZ = resultList;
				bindingofPZZ(resultList);
				
			}
		},this);
	}catch(NullPointerException e){
		android.app.AlertDialog.Builder builderofPZZf = new AlertDialog.Builder(PossibleZZ.this);
		builderofPZZf.setMessage("无返回值, 请用其他数据");
		builderofPZZf.create().show();
	}

		
	}

}
